{% import "@SyliusAdmin/Common/Macro/money.html.twig" as money %}


{% set orderPromotionAdjustment = constant('Sylius\\Component\\Core\\Model\\AdjustmentInterface::ORDER_PROMOTION_ADJUSTMENT') %}
{% set orderShippingPromotionAdjustment = constant('Sylius\\Component\\Core\\Model\\AdjustmentInterface::ORDER_SHIPPING_PROMOTION_ADJUSTMENT') %}
{% set itemPromotionAdjustment = constant('Sylius\\Component\\Core\\Model\\AdjustmentInterface::ORDER_ITEM_PROMOTION_ADJUSTMENT') %}
{% set shippingAdjustment = constant('Sylius\\Component\\Core\\Model\\AdjustmentInterface::SHIPPING_ADJUSTMENT') %}
{% set taxAdjustment = constant('Sylius\\Component\\Core\\Model\\AdjustmentInterface::TAX_ADJUSTMENT') %}

{% set orderShippingPromotions = sylius_aggregate_adjustments(order.getAdjustmentsRecursively(orderShippingPromotionAdjustment)) %}

<tr>
    <th colspan="8" id="items-total" class="right aligned">
        <strong>{{ 'sylius.ui.subtotal'|trans }}</strong>:
        {{ money.format(order.itemsTotal ,order.currencyCode) }}
    </th>
</tr>
<tr>
    <td colspan="{{ orderShippingPromotions ? 2 : 4 }}" id="shipping-charges">
        {% if not order.adjustments(shippingAdjustment).isEmpty() %}
            <div class="ui relaxed divided list">
                {% for adjustment in order.adjustments(shippingAdjustment) %}
                    <div class="item">
                        <div class="content">
                            <span class="header">{{ adjustment.label }}</span>
                            <div class="description">
                                {{ money.format(adjustment.amount, order.currencyCode) }}
                            </div>
                        </div>
                    </div>
                {% endfor %}
            </div>
        {% else %}
            <p><small>{{ 'sylius.ui.no_shipping_charges'|trans }}</small></p>
        {% endif %}
    </td>
    {% if not orderShippingPromotions is empty %}
    <td colspan="2" id="promotion-shipping-discounts">
        <div class="ui relaxed divided list">
            {% for label, amount in orderShippingPromotions %}
                <div class="item">
                    <div class="content">
                        <div class="header">{{ label }}</div>
                        <div class="description">
                            {{ money.format(amount, order.currencyCode) }}
                        </div>
                    </div>
                </div>
            {% endfor %}
        </div>
    </td>
    {% endif %}
    <td colspan="4" id="shipping-total" class="right aligned">
        <strong>{{ 'sylius.ui.shipping_total'|trans }}</strong>:
        {{ money.format(order.shippingTotal, order.currencyCode) }}
    </td>
</tr>
<tr>
    <td colspan="4" id="taxes">
        {% set taxAdjustments = order.getAdjustmentsRecursively(taxAdjustment) %}
        {% if taxAdjustments is not empty %}
            <div class="ui relaxed divided list">
                {% for taxLabel, taxAmount in sylius_aggregate_adjustments(taxAdjustments) %}
                    <div class="item">
                        <div class="content">
                            <span class="header">{{ taxLabel }}</span>
                            <div class="description">
                                {{ money.format(taxAmount, order.currencyCode) }}
                            </div>
                        </div>
                    </div>
                {% endfor %}
            </div>
        {% else %}
            <p>{{ 'sylius.ui.no_taxes'|trans }}.</p>
        {% endif %}
    </td>
    <td colspan="4" id="tax-total" class="right aligned">
        <strong>{{ 'sylius.ui.tax_total'|trans }}</strong>:
        {{ money.format(order.taxTotal ,order.currencyCode) }}
    </td>
</tr>
<tr>
    <td colspan="4" id="promotion-discounts">
        {% set orderPromotions = sylius_aggregate_adjustments(order.getAdjustmentsRecursively(orderPromotionAdjustment)) %}
        {% if not orderPromotions is empty %}
            <div class="ui relaxed divided list">
                {% for label, amount in orderPromotions %}
                    <div class="item">
                        <div class="content">
                            <span class="header">{{ label }}</span>
                            <div class="description">
                                {{ money.format(amount, order.currencyCode) }}
                            </div>
                        </div>
                    </div>
                {% endfor %}
            </div>
        {% else %}
            <p>{{ 'sylius.ui.no_promotion'|trans }}.</p>
        {% endif %}
    </td>
    <td colspan="4" id="promotion-total" class="right aligned">
        <strong>{{ 'sylius.ui.promotion_total'|trans }}</strong>:
        {{ money.format(order.orderPromotionTotal, order.currencyCode) }}
    </td>
</tr>
<tr>
    <td colspan="8" id="total" class="ui large header right aligned">
        <strong>{{ 'sylius.ui.total'|trans }}</strong>:
        {{ money.format(order.total, order.currencyCode) }}
    </td>
</tr>
